<template>
    <div id="app">
        <router-view/>
        <log v-if="useLog"/>
        <!--<div class="loading" v-if="!wechatfx" @click="wechatfx = !wechatfx"><img :src="require('@/images/logoGif.gif')"-->
                                                                                 <!--alt=""></div>-->
    </div>
</template>

<script>
    import api from './utils/api';
    import sha1 from 'js-sha1'
    import wx from 'weixin-js-sdk'
    import {flexible} from './js/flexible';
    import Log from '@/components/Log';
    import axios from 'axios'

    let useLog = false;
    try {
        useLog = require('@/../config/use_log')
    } catch (e) {

    }

    export default {
        name: 'App',
        data() {
            return {
                useLog: useLog,
                invite: [],
                host: window.location.href,
                // wechatfx: true,
                ticket: 'HoagFKDcsGMVCIY2vOjf9k4tPPJAAolVFsxXRyEembJs5A1QmnUE1FFeaRHkTBKPX5KrWy1gm1v61ytW7IV13A',
                accToken: []
            };
        },
        components: {Log},
        created() {
            flexible()
        },
        methods: {
            async wechatToken() {
                var _that = this;
                await api.request('/user', 'get', {}).then((res) => {
                    _that.invite = res.data.data;
                    _that.$root.invite = _that.invite;
                });
                let access_url = window.location.protocol + '//' + window.location.host + window.location.pathname
                api.request('/wechat_share', 'get', {access_url: access_url}).then((res) => {
                    _that.accToken = res.data;

                    wx.config({
                        debug: _that.accToken.debug,
                        appId: _that.accToken.appId, // 必填，公众号的唯一标识
                        timestamp: _that.accToken.timestamp, // 必填，生成签名的时间戳
                        nonceStr: _that.accToken.nonceStr, // 必填，生成签名的随机串
                        signature: _that.accToken.signature,// 必填，签名
                        jsApiList: _that.accToken.jsApiList
                    });
                    wx.ready(function () {
                        //分享朋友圈
                        // _that.wechatfx = true;
                        var configs = {
                            title: _that.invite.invite_title,
                            desc: _that.invite.invite_content,
                            link: _that.invite.invite_link_and,
                            imgUrl: _that.invite.invite_logo,
                            success: function() {},
                            cancel: function() {}
                        };
                        wx.updateAppMessageShareData(configs);
                        wx.updateTimelineShareData(configs);
                        wx.onMenuShareTimeline(configs);
                        wx.onMenuShareAppMessage(configs);

                    });
                })

                // wx.error(function (res) {
                //     // alert(res)
                // });

            },
        },
        watch: {
            $route(to, from) {
                if (to.path.indexOf('Login') == -1 && to.path.indexOf('Forget') == -1 && to.path.indexOf('reg') == -1) {
                    this.wechatToken();
                    // this.wechatfx = false;
                }
            }
        }
    }
</script>

<style>
    @import "./style/index.css";
    @import "./style/liMarquee.css";
    @import "./style/swiper-3.2.7.min.css";
    @import "style/wokrdeilte.css";
    @import "./style/public.css";
    @import "./style/workAll.css";
    @import "./style/TaskStatus.css";

    .loading {
        background: rgba(0, 0, 0, .5);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
    }

    .loading img {
        width: 2rem;
        position: absolute;
        left: 50%;
        margin-left: -1rem;
        top: 50%;
        margin-top: -1rem;
    }
</style>
